var Dataset = require('../models').Dataset;
var Showcase = require('../models').Showcase;
var User = require('../models').User;
var moment = require('moment');
var settings = require('../settings');

module.exports.index = function(req,res){
  var result = {user: req.session.user || null}
  return res.render('index.jade', result);
}
module.exports.datasets = function(req,res){
  var page = parseInt(req.query.page,10) || 1;
  page = page > 0 ? page : 1;
  Object.keys(req.query).map(function(k){
    if(req.query[k] == "all"){
      delete req.query[k]
    }
  })
  var result = {user: req.session.user || null};
  Dataset.find(req.query).exec()
  .then(function(datasets){
    result.datasets = datasets
    return res.render('datasets',result);
  })
  //
}
